//https://www.nowcoder.com/practice/1c82e8cf713b4bbeb2a5b31cf5b0417c?tpId=13&tqId=23258&ru=%2Fpractice%2Fe8a1b01a2df14cb2b228b30ee6a92163&qru=%2Fta%2Fcoding-interviews%2Fquestion-ranking&sourceUrl=%2Fexam%2Foj%2Fta%3Fpage%3D1%26tpId%3D13%26type%3D13
//思想：借用系统的map实现；
//思想：自己实现一个hash数组；

#include <iostream>
#include <string>
#include <vector>
#include <map>

using namespace std;

#include <cstddef>
class Solution1 {
public:
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param str string字符串 
     * @return int整型
     */
    int FirstNotRepeatingChar(string str) {
        // write code here
        std::map<char,int> m_map;
        int index=-1;
        for(size_t i=0;i<str.size();++i){
            ++m_map[str[i]];
        }
        for(size_t i=0;i<str.size();++i){
            if(m_map[str[i]] == 1) {
                index =i;
                break;
            }
        }
        return index;

    }
};

class Solution2 {
public:
    int FirstNotRepeatingChar(string str) {
        if (str.empty()) {
            return -1;
        }
        const int tableSize = 256;
        unsigned int hashTable[tableSize]{0};
        for (unsigned int i =0;i<str.length();++i)
        {
            auto val = hashTable[str.at(i)];
            hashTable[str.at(i)] = ++val;
        }
        for (unsigned int i = 0; i < str.length(); ++i)
        {
            auto val = hashTable[str.at(i)];
            if (val == 1) {
                return i;
            }
        }
        return -1;
    }
};